// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import router from './router'
import apisettings from './js/apiSettings'
import http from './js/http'
import GeminiScrollbar from 'vue-gemini-scrollbar'
// eslint-disable-next-line camelcase
import global_variable from './js/global_variable'
import Router from 'vue-router'
import moment from "moment"

Vue.prototype.$moment = moment;
Vue.use(GeminiScrollbar)
Vue.config.productionTip = false
Vue.prototype.$http = http
Vue.prototype.$api = apisettings
Vue.prototype.$userInfo = {
  name: '宠与崇',
  id: '123',
  avatar: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574665054423&di=da6fb024901f8c8a9671d7dee3f7b0f2&imgtype=0&src=http%3A%2F%2F00imgmini.eastday.com%2Fmobile%2F20180917%2F20180917195244_a88f796788f3c6a62cbeeccca650fcbf_5.jpeg'
}
Vue.prototype.$global_variable = global_variable
Vue.use(ElementUI)
/* eslint-disable no-new */
router.beforeEach((to, from, next) => {
    // 每次路由之前判断，如果已经登录，则可以路由
  if(to.path === '/'){
    next('/app')
  }
    if (localStorage.getItem('uid')) {
      next()
      // eslint-disable-next-line brace-style
    }
    // 如果要去的页面不是不需要登录的页面
    else if (to.meta.notNeedLogin === undefined) {
      if (!window.localStorage.uid) {
        // 如果没有data
        console.log('当前用户需要登录'+ to.meta.notNeedLogin),
          next('/login')
      } else {
        // login一些操作
        console.log('登录成功')
        next()
      }
    } else {
      next()
    }
  }
)




new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
